package example.data;

/**
 * Created by lenovo on 2016/11/7 0007.
 * 栈的实现
 */
public class StackDemo {
    private int maxSize;
    private long[] stackArray;
    private int top;

    private StackDemo(int s) {
        maxSize = s;
        stackArray = new long[maxSize];
        top = -1;
    }

    private void push(long j) {
        stackArray[++top] = j;
    }

    private long pop() {
        return stackArray[top--];
    }

    public long peek() {
        return stackArray[top];
    }

    private boolean isEmpty() {
        return (top == -1);
    }

    public boolean isFull() {
        return (top == maxSize - 1);
    }

    public static void main(String[] args) {
        StackDemo theStack = new StackDemo(10);
        theStack.push(10);
        theStack.push(20);
        theStack.push(30);
        theStack.push(40);
        theStack.push(50);
        while (!theStack.isEmpty()) {
            System.out.print(theStack.pop() + " ");
        }
        System.out.println("");
    }
}
